<html>
  <body>
    <div class="container">
      <button type="button" onclick="test()">测试1</button>
      <button type="button" onclick="test2()">测试2</button>
      <button type="button" onclick="test3()">测试3</button>
    </div>

    <script type="text/javascript">
      var strOne = "张三";
      let strTwo = "李四";
      function test() {
        const cars = ["Tesla", "Volvo", "BMW"];
        let str = "AAA_12123";
        // 判断以字符串开头
        if (str.substr(0, 4) === "AAA_") {
          console.log(1);
        }
        if (str.substring(0, 4) === "AAA_") {
          console.log(2);
        }
        if (str.search("AAA_") != -1) {
          console.log(3);
        }
        if (new RegExp("^AAA_.*$").test(str)) {
          console.log(4);
        }
        if ("AAA_".match(new RegExp("^AAA_.*$"))) {
          console.log(5);
        }

        // 合并两个对象的值
        var objOne = { a: "123", b: "123", c: "123", d: "123" };
        var objTwo = { e: "123", f: "123", g: "123", h: "123" };
        Object.assign(objOne, objTwo);
        console.log(objOne);
        console.log(objTwo);

        // 挑选对象中符合条件的 key value
        var objThree = { a: "123", b: "123", c: "123", d: "123" };
        var objFour = {};
        for (let key in objThree) {
          if (key === "a" || key === "d") {
            continue;
          }
          objFour[key] = objThree[key];
        }
        console.log(objFour);
      }

      function test2() {
        console.log(window.strOne);
        console.log(window.strTwo);
      }
      // 方法2， 遍历字符串
      function unicode2Ch(str){
          if(!str){
            return;
          }
          // 控制循环跃迁
          var len = 1;
          var result = '';
                // 注意，这里循环变量的变化是i=i+len 了
          for (var i = 0; i < str.length; i=i+len) {
            len = 1;
            var temp = str.charAt(i);
            if(temp == '\\'){
              // 找到形如 \u 的字符序列
              if(str.charAt(i+1) == 'u'){
                // 提取从i+2开始(包括)的 四个字符
                var unicode = str.substr((i+2),4); 
                                        // 以16进制为基数解析unicode字符串，得到一个10进制的数字
                result += String.fromCharCode(parseInt(unicode,16).toString(10));
                // 提取这个unicode经过了5个字符， 去掉这5次循环
                len = 6;
              }
              else{
                result += temp;
              }
            }
            else{
              result += temp;
            }
          }
          return result;
      }

      function decodeUnicode(str) {
        return str.replace(/([\u4E00-\u9FA5]|[\uFE30-\uFFA0])/g,function(){
          return "\\u" + RegExp["$1"].charCodeAt(0).toString(16);
        });
    }


      function test3() {
          let arr = [-27, -115, -107, -26, -115, -82, -26, -119, -109, -27, -115, -80, -27, -121, -70, -23, -108, -103, -17, -68, -102, 47, 32, 98, 121, 32, 122, 101, 114, 111]
          debugger  
        // let str ='\u5355\u636e\u6253\u5370\u51fa\u9519\uff1a\u2f\u20\u62\u79\u20\u7a\u65\u72\u6f'
        unicode2Ch(str)
        debugger

      }

      function toChineseWords(data){
        if(data == '' || typeof data == 'undefined') return '请输入十六进制unicode';
        data = data.split("\\u");
        var str ='';
        for(var i=0;i<data.length;i++){
          str+=String.fromCharCode(parseInt(data[i],16).toString(10));
        }
        return str;
      }



      function test4(arr){
        if (typeof arr === 'string') {
            return arr;
        }
        var str = '',
            _arr = arr;
        for (var i = 0; i < _arr.length; i++) {
            var one = _arr[i].toString(2),
                v = one.match(/^1+?(?=0)/);
            if (v && one.length == 8) {
                var bytesLength = v[0].length;
                var store = _arr[i].toString(2).slice(7 - bytesLength);
                for (var st = 1; st < bytesLength; st++) {
                    store += _arr[st + i].toString(2).slice(2);
                }
                str += String.fromCharCode(parseInt(store, 2));
                i += bytesLength - 1;
            } else {
                str += String.fromCharCode(_arr[i]);
            }
        }
        return str;
      }

      
    </script>
  </body>
  <style type="text/css">
    .container {
      margin: 0 auto;
    }
  </style>
</html>
